package com.kaifamiao.jdbc.meta;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class GetDatabaseMetaData {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        /*
        String driverClassName = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/kaifamiao?serverTimezone=Asia/Chongqing";
        String username = "kfm";
        String password = "kfm";
        */

        String driverClassName = "oracle.jdbc.OracleDriver";
        String url = "jdbc:oracle:thin:@localhost:1521:kaifamiao";
        String username = "kaifamiao";
        String password = "kaifamiao";

        // 加载并注册驱动
        Class.forName( driverClassName );
        // 建立连接
        Connection conn = DriverManager.getConnection( url, username, password );

        // 通过数据库连接可以获得数据库元数据
        DatabaseMetaData meta = conn.getMetaData();

        System.out.println( "数据库名称: " + meta.getDatabaseProductName() ) ;
        System.out.println( "数据库版本: " + meta.getDatabaseProductVersion() ) ;
        System.out.println( "数据库驱动名称: " + meta.getDriverName() ) ;
        System.out.println( "数据库驱动版本: " + meta.getDriverVersion() ) ;

        // 关闭连接
        conn.close();

    }

}
